package com.hotel.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hotel.entity.OrderResult;
import com.hotel.entity.RoomInfo;
import com.hotel.service.OrderService;
import com.hotel.utils.Message;





//处理预约模块的类型筛选、服务预定、预定认证

@Controller
@RequestMapping("/order")
public class OrderController {
	
	@Resource  
    private OrderService orderService; 
	
	@ResponseBody
	@RequestMapping(value="/type/{id}/{floor_no}/{room_type}", method=RequestMethod.GET)  
    public List<RoomInfo> typeSelectToGet(@PathVariable("id") int id, @PathVariable("floor_no") int floor_no,@PathVariable("room_type") String room_type){  
		List<RoomInfo> list = orderService.typeSelect(id, floor_no, room_type);
		
		return list;
    }  
    
	@ResponseBody
	@RequestMapping(value="/type/{id}/{floor_no}", method=RequestMethod.GET)  
    public List<RoomInfo> typeSelectToGet(@PathVariable("id") int id, @PathVariable("floor_no") int floor_no){  
		List<RoomInfo> list = orderService.typeSelect(id, floor_no);
		
		return list;
    } 
	
	@ResponseBody
	@RequestMapping(value="/type/{id}/{room_type}", method=RequestMethod.GET)  
    public List<RoomInfo> typeSelectToGet(@PathVariable("id") int id, @PathVariable("room_type") String room_type){  
		List<RoomInfo> list = orderService.typeSelect(id, room_type);
		
		return list;
    } 

	@ResponseBody
    @RequestMapping(value="/service", method=RequestMethod.POST)  
    public OrderResult serviceOrderToPost(@RequestBody int room_info_id, HttpServletRequest request,HttpServletResponse response){
		
		OrderResult or = new OrderResult();
    	String message = Message.Message_6000;
    	
    	String username;
    	username = (String) request.getSession().getAttribute("account");
    	
    	System.out.println(username);
    	
    	if(null != username){
    		message = orderService.orderVerify(room_info_id);
    	}
    	else if(null == username || "" == username){
    		or.setMessage(message);
    		or.setRoomInfo(null);
    	}
    	
    	if(message == Message.Message_7001){
    		or = orderService.orderRoom(room_info_id);
    	}
    	
    	if(message == Message.Message_7000){
    		
    	}
    	else{
    		or.setMessage(message);
    		or.setRoomInfo(null);
    	}
    	return or;
    }  
    
}
